/********************************************************************
	Created:		2011/11/06   20:54
	Filename: 		ComDefinition.h
	Author:			Zhaohua Wang
	Description:	N/A
*********************************************************************/
#pragma once
#pragma warning(disable : 4996)

/*
m_mapCmdID[L"LineDisplay"] = IDC_BTN_CHECK_LD;
m_mapCmdID[L"Printer"] = IDC_BTN_CHECK_PRINTER;
m_mapCmdID[L"CashDrawer"] = IDC_BTN_CHECK_CD;
m_mapCmdID[L"Monitor"] = IDC_BTN_CHECK_MONITOR;
m_mapCmdID[L"MSR"] = IDC_BTN_CHECK_MRS;

m_mapCmdID[L"RFID"] = CMD_CHECK_RFID;
m_mapCmdID[L"Keyboard"]    = CMD_CHECK_KB;
m_mapCmdID[L"P-Keyboard"]  = CMD_CHECK_PKB;
m_mapCmdID[L"iButton"] = CMD_CHECK_IBTN;
m_mapCmdID[L"ICCard"] = CMD_CHECK_ICCD;
m_mapCmdID[L"Bluetooth"] = CMD_CHECK_BLUETH;
m_mapCmdID[L"Memery"] = WM_CHECK_MEM;
m_mapCmdID[L"COM"] = WM_CHECK_COM;
m_mapCmdID[L"WIFI"] = WM_CHECK_WIFI;
m_mapCmdID[L"FAN"] = WM_CHECK_FAN;
m_mapCmdID[L"Disk"] = WM_CHECK_HDISK;
m_mapCmdID[L"Scanner"] = WM_CHECK_SCANNER;
*/

typedef enum _EDeviceType
{
    ED_LineDisplay,
    ED_Printer,
    ED_CashDrawer,
    ED_MONITOR,
    ED_MRS,
    ED_Keyboard,
    ED_Biometrics,
    ED_Count
}EDeviceType;

typedef enum _EPrinterType
{
    EUnkownPrinter = -1,
    T90,
    POS88VI,
    PR58,
    EPrintertypeCount
}EPrinterType;

const static CString PrinterName[EPrintertypeCount+1] =
{
    _T("T90"),
    _T("POS88VI"),
    _T("PR58"),
    _T("Unkown")
};

typedef enum _ECashdrawerType
{
    EUnknownCashdrawer = -1,
    EComCashdrawer,
    EPrinterwithCashdrawer,
    ELDwithCashdrawer,
	EMBCashdrawer
}ECashdrawerType;

#define CD_STATUS_OPEN          0
#define CD_STATUS_CLOSE         1
#define CD_STATUS_UNKNOWN -1

typedef enum _EPort
{
    EUnkownPort /*= -1*/,
    COM1,
    COM2,
    COM3,
    COM4,
    COM5,
    COM6,
    //COM7,
    //COM8,
    LPT1,
    LPT2,
    LPT3,
    USB1,
    USB2,
    USB3,
    USB4,
    EPortCount
}EPort;
const static CString PortName[EPortCount] = {
    _T("None"),
    _T("COM1"),
    _T("COM2"),
    _T("COM3"),
    _T("COM4"),
    _T("COM5"),
    _T("COM6"),
    _T("LPT1"),
    _T("LPT2"),
    _T("LPT3"),
};

typedef enum _ELineDisplayType
{
    EUnknownLineDisplay = -1,
    VC220,
    VC110,
    ELineDsiplayTypeCount
}ELineDisplayType;
const static CString LineDisplayName[ELineDsiplayTypeCount + 1] = {
    _T("VC220"),
    _T("VC110"),
    _T("None")
};

typedef enum _EMainboardType
{
    EUnkownMainboard = -1,
    M335,
	D525,
	N2600,
    N2600JF,
    EMainboardTypeCount
}EMainboardType;

const static CString MainBordName[EMainboardTypeCount+1] = {
    _T("MS-9866"),
    _T("Undefined")
};

typedef struct _TSysConfig
{
   int nPrinterType;
   int nPrinterPort;
   int nLineDisplayType;
   int nLineDisplayPort;
   int nMainboardType;
   int nCashDrawerPort;
   int nCashDrawerType;

   BOOL bPTwithCD;
   BOOL bLDwithCD;
   BOOL bMBwith1stCD;
   // need to optimization, only for GPIO PIN
   int m_nPIN;

   BOOL bMBwith2ndCD;
   BOOL bPTwithCut;
   int nComCount;
   int nLPTCount;

   int nPrinterInterval;
   int nLineDisplayInterval;
   int nCashdrawerInterval;
   int nSavedataInterval;
   int nPortburinInterva;
   int nTotalBurinHours;
   int nCheckInterval;

   /*int nLPT1;
   int nLPT2;
   int nLPT3;*/

   CString strConfigFile;

   // For production test.
   BOOL bPT;
   CString strPTLog;
   BOOL bPTFinished;
}TSysConfig;

typedef enum _EDeviceStatus
{
    ES_Normal = 0,
    ES_Pass,
    ES_Unchecked,
    ES_Exception,
    ES_Reserve
}EDeviceStatus;

#define HOME_WEB_SITE           _T("http://www.purongtech.com")
static const CString SYSTEM_CONFIGUTATION_DEF(L"\\system\\System.inf");

//////////////////////////////////////////////////////////////////////////
// Self defined message
#define WM_UPDATE_CONFIGURATEION					    WM_USER + 1
#define WM_CHECK_LINEDISPLAY                               WM_USER + 2
#define WM_CHECK_PRINTER                                     WM_USER + 3
#define WM_CHECK_CASHDRAWER                             WM_USER + 4
#define WM_CHECK_MRS                                           WM_USER + 5
#define WM_CHECK_KEYBOARD                                  WM_USER + 6
#define WM_CHECK_BIOMETRICS                               WM_USER + 7
#define WM_CHECK_CAMERA                                     WM_USER + 8
#define WM_BURNIN_START                                      WM_USER + 9
#define WM_BURNIN_END                                         WM_USER + 10
#define WM_BURNIN_PROGRESS_UPDATE                   WM_USER + 11

#define WM_LD_ERROR_OCCUR                                  WM_USER + 12
#define WM_PRINTER_ERROR_OCCUR                         WM_USER + 13
#define WM_CD_ERROR_OCCUR                                 WM_USER + 14

#define  WM_INIT_CONNECTPORT                             WM_USER + 15
#define  WM_CLOSE_CONNECTPORT                          WM_USER + 16
#define  WM_CASHDRAWER_STATUS_UPDATE             WM_USER + 17

#define WM_INIT_LDCHECK_DLG                                WM_USER + 18

#define WM_PT_LD                                                    WM_USER + 19
#define WM_PT_PRINTER                                           WM_USER + 20
#define WM_PT_CD                                                    WM_USER + 21
#define WM_PT_MONITOR                                         WM_USER + 22
#define WM_PT_MSR                                                 WM_USER + 23

#define WM_CHECK_MONITOR                                  WM_USER + 24
#define WM_CHECK_MSR                                           WM_USER + 25

#define CMD_CHECK_RFID                                          WM_USER + 26
#define WM_CHECK_RFID                                           WM_USER + 27
#define CMD_CHECK_KB                                            WM_USER + 28
#define WM_CHECK_KB                                              WM_USER + 29
#define CMD_CHECK_PKB                                           WM_USER + 30
#define WM_CHECK_PKB                                            WM_USER + 31
#define CMD_CHECK_IBTN                                         WM_USER + 32
#define WM_CHECK_IBTN                                          WM_USER + 33
#define CMD_CHECK_ICCD                                         WM_USER + 34
#define WM_CHECK_ICCD                                          WM_USER + 35
#define CMD_CHECK_BLUETH                                     WM_USER + 36
#define WM_CHECK_BLUETH                                      WM_USER + 37

#define WM_CHECK_MEM                                         WM_USER + 38
#define WM_CHECK_COM                                         WM_USER + 39
#define WM_CHECK_WIFI                                          WM_USER + 40
#define WM_CHECK_FAN                                          WM_USER + 41
#define WM_CHECK_HDISK                                       WM_USER + 42
#define WM_CHECK_SCANNER                                  WM_USER + 43
//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////
// Error code & description
const static int ErrorAccount = 5;
const static CString ErrorDes[ErrorAccount] = {
    _T("Normal"),
    _T("Fail to open port"),
    _T("Unknown"),
    _T("Unknown"),
    _T("Unknown"),
};

// COM R/W
HANDLE PR_OpenCom(int nCom, OVERLAPPED &oWrite, OVERLAPPED &oRead, int nParity, int &nError);

BOOL PR_SendStr2Com(HANDLE hCom, LPCTSTR lpStr, int nLength, OVERLAPPED &oWrite);
BOOL PR_SendStr2Com(HANDLE hCom, char *pStr, int nLength, OVERLAPPED &oWrite);

BOOL PR_ReadStrFromCom(HANDLE hCom, LPTSTR pStr, int nLen, OVERLAPPED &oRead);
BOOL PR_ReadStrFromCom(HANDLE hCom, char *pStr, int nLen, OVERLAPPED &oRead);

BOOL PR_CloseCom(HANDLE hCom, OVERLAPPED &oWrite, OVERLAPPED &oRead);

// LPT R/W
HANDLE PR_OpenLPT(int nLPT, OVERLAPPED &oWrite, OVERLAPPED &oRead, int &nError);

BOOL PR_CloseLPT(HANDLE hLPT, OVERLAPPED &oWrite, OVERLAPPED &oRead);

BOOL PR_SendStr2LPT(HANDLE hCom, char* lpStr, int nLength, OVERLAPPED &oWrite);

BOOL PR_ReadStrFromLPT(HANDLE hCom, char* szBuf, int nLen, OVERLAPPED &oRead);
